'use strict';

function BlogPublishCtrl($http, $cookies, UserService) {
	if(!UserService.isLogin()) return false;

	$('.publishBtn').on('click', function(e){
		e.preventDefault();
		var ue = UE.getEditor('container'),

		url = '/ajax/blog/publish',
		params = {
			'title': $('.pfInput').val(),
			'author_id': $cookies.get('_id'),
			'author_name': $cookies.get('name'),
			'content': ue.getContent(),
			'describe': ue.getContentTxt(),
		};

		$.get(url, params, function(res) {
			console.log(params);
			if(!res.stat) {
				alert("发布成功");
				window.location.href = "/templates/blog/list.html"
			} else {
				alert("发布失败");
				console.log(res.error);
			}
		});
	});
 
}

angular.module('hzyw')
.controller('BlogPublishCtrl', BlogPublishCtrl)


